//juraj piovar after 1 s

$(document).ready(function(){
	




	
var ct = 0; 

	$("#div2").hide();
	

	
	$("#div1").hover(function(e){
		
		
		if(e.type==="mouseenter"){
			
			$("#div2").delay("5000").fadeIn();
			console.log(e);
			console.log("do ");
			
		}
		
		
		if(e.type==="mouseleave"){
			
			$("#div2").delay("5000").fadeOut();
			console.log(e);
			console.log("prec ");
		}
		
		


		ct++;
		
		for(var i=0;i<100;i++){
			
			$("#div3").delay("10000").text(i);

		}


		
		

	});
	
	
		






		var j = 0;
		
		setInterval(function(){   //setTimeout		
			
			j++;
			
			$("#div4").text(j);
			//do something special
		}, 1000);





		$("#div5").mouseover(function(){
		
			$("#div5").text("v objekte");
		
		});
		
		
		$("#div5").mouseout(function(){
		
			$("#div5").text("mimo objektu");
		
		});



$("body").mousemove(function(){
	
	var d3 = $("#div3").position(),
		d3w = $("#div3").width(),
		d3h = $("#div3").height(); 
		
	var d5 = $("#div5").position(),
		d5w = $("#div5").width(),
		d5h = $("#div5").height(); 		
	
		
	console.log(d3.top+"  "+d3.left+"  "+d3w+" "+d3h);
	
	
	if((d3.top>=d5.top)&&(d3.top+d3h<=d5.top+d5h)&&(d3.left>=d5.left)&&(d3.left+d3w<=d5.left+d5w)){
		
	 console.log("v");	
	}
	
	
	 $("body").mouseup(function(){
		 
		 if((d3.top>=d5.top)&&(d3.top+d3h<=d5.top+d5h)&&(d3.left>=d5.left)&&(d3.left+d3w<=d5.left+d5w)){
		 
		//alert("aaaaaaaaaaaaaaa"); 
		$("#div3").css({"position":"absolute"}).animate({"top":d5.top,"left":d5.left}); 
		
		}
	 });
	 
	
	
	

	

});






$("body").mousedown(function(er){

	console.log(er.type);

});



/*
$("body").mouseup(function(er){

	console.log(er.type);
	

	

});

*/


$("#div5").css({"z-index":"1"});

$("#div3").css({"z-index":"100"});

$("#div3").draggable();







});






